package cn.sumpu.app.coolsk.web.intercept;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import cn.sumpu.app.coolsk.biz.ContentBiz;
import cn.sumpu.app.coolsk.domain.Content;


public class ControllerIntercept implements HandlerInterceptor {

	private ContentBiz contentBiz;
	
	public void setContentBiz(ContentBiz contentBiz) {
		this.contentBiz = contentBiz;
	}

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		//帮助
		List<Content> help = contentBiz.getContentByChannel("dc0dfdb2-6656-4e47-ac95-0dda1f259497", 1);
		request.setAttribute("help", help); 
		//底部
		List<Content> footer = contentBiz.getContentByChannel("eb2c95e7-a239-492b-93e1-8be0217cfe09", 1);
		request.setAttribute("footer", footer);
		//合作网站
		List<Content> cooperatesite = contentBiz.getContentByChannel("b08f51d7-9c7e-44eb-978b-188a39a96f72", 1);
		request.setAttribute("cooperatesite", cooperatesite);
		//友情链接
		List<Content> friendlink = contentBiz.getContentByChannel("3e233a7e-d475-44ac-bb13-cf0ae6ec9820", 1);
		request.setAttribute("friendlink", friendlink);
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
	}

}
